from itsdangerous import TimedJSONWebSignatureSerializer as TJWSS
from django.conf import settings


def encode_openid(openid):
    tjwss = TJWSS(secret_key=settings.SECRET_KEY, expires_in=60)
    encode_data = tjwss.dumps({"openid": openid})

    return encode_data.decode()


def decode_openid(encode_data):
    tjwss = TJWSS(secret_key=settings.SECRET_KEY, expires_in=60)
    try:
        decode_data = tjwss.loads(encode_data)
        openid = decode_data.get('openid')
        return openid
    except Exception as e:
        pass
